<!-- 营销推广 -->
<template>
  <view>
    <view class="bg" @click="clickFn">
      <image src="/static/img/washCar/washCarShare.jpg" mode="aspectFit" />
    </view>
    <share-popup
      v-model="sharePopupShow"
      :showDownload="true"
      @change="handleShare"
      @close="closePopup"
    ></share-popup>
  </view>
</template>

<script>
import sharePopup from './components/sharePopup.vue'
import { share } from '@/utils/common-api.js'

export default {
  data() {
    return {
      url: 'https://files.yzsheng.com/bussiness/imgs/washCar/washCarShare.jpg',
      sharePopupShow: false,
    }
  },

  methods: {
    clickFn() {
      this.sharePopupShow = true
    },

    handleShare(e) {
      if (e === 'download') {
        this.sharePopupShow = false
        // #ifndef H5
        uni.showLoading()
        uni.saveImageToPhotosAlbum({
          filePath: this.url,
          success: () => {
            uni.hideLoading()
            uni.showToast({
              title: '已保存到相册',
              duration: 2000,
            })
          },
          fail: () => {
            uni.hideLoading()
            uni.showToast({
              title: '下载失败',
              duration: 2000,
            })
          },
        })
        // #endif
      } else {
        share(
          {
            type: 2,
            scene: e,
            imageUrl:this.url,
          },
          (status) => {
            this.sharePopupShow = false
            if (status) {
              console.log(41)
            } else {
              uni.showToast({
                title: '分享失败',
                duration: 2000,
                icon: 'none',
              })
            }
          }
        )
      }
    },

    closePopup(e) {
      console.log(e)
      this.sharePopupShow = false
    },
  },

  components: {
    sharePopup,
  },
}
</script>

<style lang="scss" scoped>
.bg {
  width: 100vw;
  height: 100vh;
  background: #f6f6f6;
  padding: 20rpx 50rpx;

  image {
    height: 100%;
    width: 100%;
    border-radius: 10rpx;
  }
}

.popup-wrap {
  width: 100vw;
  height: 100vh;

  z-index: 1;
}
</style>
